import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpService } from '../../../service/http.service';
import { NzCardModule } from 'ng-zorro-antd/card';
import { NzTagModule } from 'ng-zorro-antd/tag';

@Component({
  selector: 'app-logdetail',
  templateUrl: './logdetail.component.html',
  styleUrls: ['./logdetail.component.css'],
})
export class LogdetailComponent {
  public studyInfo: any = {
    id: 0,
    content: '',
    logDate: null,
    name: '',
    comment: '',
    tagName: '',
  };

  tagList: string[] = [];

  tagBackgroundMap: { [key: string]: string } = {
    '常见Bug': 'bg-bug',
    '算法学习': 'bg-algo',
    '文章总结': 'bg-article',
    '项目设计': 'bg-project',
    '需求分析': 'bg-analysis',
  };

  constructor(
    private router: ActivatedRoute,
    private httpService: HttpService,
  ) {}

  ngOnInit() {
    const id = this.router.snapshot.queryParams['id'];
    this.getDetailById(id);
  }

  private getDetailById(id: any) {
    const url = '/rest/study/' + id;
    return this.httpService.get(url).subscribe((res: any) => {
      this.studyInfo.id = res.data.id;
      this.studyInfo.content = res.data.content;
      this.studyInfo.logDate = res.data.logDate;
      this.studyInfo.name = res.data.name;
      this.studyInfo.comment = res.data.comment;
      this.studyInfo.tagName = res.data.tagName;
      console.log('接口返回：', res.data);
      console.log('tagName字段：', res.data.tagName);
    });
  }

  getHeaderBackgroundClass(): string {
    if (!this.studyInfo.tagName || this.studyInfo.tagName.length === 0) return 'bg-default';

    const matchedTag = this.studyInfo.tagName.find((tag: string) => this.tagBackgroundMap[tag]);
    return this.tagBackgroundMap[matchedTag] || 'bg-default';
  }

}
